package com.wang.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
// import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Classname Swagger2Config
 * @Description TODO
 * @Date 2025/3/20 9:33
 * @Created by pc
 */
@Configuration
@EnableSwagger2
@EnableWebMvc // 2.6.5以上的springboot 需要加这个注解
public class Swagger2Config {

    @Bean
    public Docket apiDocket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .apis(RequestHandlerSelectors.basePackage("com.wang.controller.api"))
                //.paths(PathSelectors.any())
                .build().apiInfo(apiInfo())
                .groupName("前台接口");
    }

    @Bean
    public Docket adminDocket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .apis(RequestHandlerSelectors.basePackage("com.wang.controller.admin"))
                //.paths(PathSelectors.any())
                .build().apiInfo(apiInfo())
                .groupName("后台接口");
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("66项目接口文档")
                .description("66班电商项目接口测试文档")
                .version("0.0.1")
                .contact(new Contact("wang","https://www.baidu.com","110@qq.com"))
                .termsOfServiceUrl("https://www.baidu.com")
                .license("")
                .build();
    }

    // @Bean
    // public WebMvcConfigurerAdapter webMvcConfigurerAdapter() {
    //     return new WebMvcConfigurerAdapter() {
    //         @Override
    //         public void addResourceHandlers(ResourceHandlerRegistry registry) {
    //             registry.addResourceHandler("/swagger-ui.html**")
    //                     .addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
    //             registry.addResourceHandler("/webjars/**")
    //                     .addResourceLocations("classpath:/META-INF/resources/webjars/");
    //         }
    //     };
    // }

}
